﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EmbeddedSharp.Core {
    public class Expression {

        protected string expr;

        public Node ExpressionTree {
            get;
            private set;
        }

        protected ExpressionParser parser = null;

        public Expression() {
        }

        public Expression(string expr) {
            this.expr = expr;

            ExpressionParser parser = DefaultDependencyManager.Instance.ParserFactory.CreateParser(this.expr);
            ExpressionTree = parser.Parse();
        }

        public object Evaluate() {
            return ExpressionTree.Evaluate();
        }

        /// <summary>
        /// Translate into another language
        /// </summary>
        /// <param name="translator"></param>
        /// <returns></returns>
        public string Translate(IExpressionTranslator translator) {
            return translator.Translate(ExpressionTree);
        }

        public override string ToString() {
            return expr;
        }
    }
}
